home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / doc / discover1 / Programming < prev    next >
Encoding:
Text File  |  2005-03-28  |  3.6 KB  |  107 lines

  1. Programming guide with detect library 
  2.  
  3. I - How-to link with libdetect?
  4.  
  5.     If you use autoconf, you need to modify configure.in and check if 
  6.     detect is installed properly on system:
  7.  
  8.     Example:
  9.  
  10.   +----8<---------------------------------------------------------------
  11.   |AC_CHECK_LIB(detect, report_detect, , 
  12.   |                            AC_MSG_ERROR(Can't find detect library!))
  13.   +----8<---------------------------------------------------------------
  14.  
  15.     Maybe you'll want to add a '--with-detect-prefix' parameters to 
  16.     allow compilation on system with a libdetect location different 
  17.     than /usr:
  18.  
  19.   +----8<---------------------------------------------------------------
  20.   |AC_ARG_WITH(detect_prefix, 
  21.   |      [  --with-detect-prefix=PFX Prefix where detect is installed], 
  22.   |      DETECT_PATH="$withval", DETECT_PATH="/usr/local")
  23.   +----8<---------------------------------------------------------------
  24.  
  25.     You also need to modify Makefile.am. Consult automake and autoconf 
  26.     info pages.
  27.  
  28.     However you use static Makefile, Add -ldetect to LDFLAGS.
  29.  
  30.  
  31. II - Include detect header file
  32.  
  33.     Include detect.h header file into your source code. 
  34.  
  35.   +----8<---------------------------------------------------------------
  36.   |#include <detect.h> 
  37.   +----8<---------------------------------------------------------------
  38.  
  39.  
  40. III - Use detect API
  41.  
  42.     You can use detect API documentation file that contains all detect 
  43.     functions and their uses.
  44.  
  45.     I recommend to make a sync before all detection operation. Because 
  46.     some criticals parts as isa, modem and mouse detection cand freeze 
  47.     your system.
  48.  
  49.     If you want to use isa/pci/pcmcia/scsi/usb detection you need to initialize lst 
  50.     files shipped with detect library. Use the 
  51.  
  52.  
  53.   +----8<---------------------------------------------------------------
  54.   |#define ISA_LST "/usr/share/detect/isa.lst"
  55.   |#define PCI_LST "/usr/share/detect/pci.lst"
  56.   |#define PCMCIA_LST "/usr/share/detect/pcmcia.lst"
  57.   |#define USB_LST "/usr/share/detect/usb.lst"
  58.   |
  59.   | struct cards_lst *lst;
  60.   | struct isa_info *isa;
  61.   | struct pci_info *pci;
  62.   |    struct usb_info *usb:
  63.   |    struct pcmcia_info *pcmcia;
  64.   |
  65.   | lst = init_lst(ISA_LST, PCI_LST, PCMCIA_LST, USB_LST);
  66.   +----8<---------------------------------------------------------------
  67.  
  68.     Here we've hardcoded pci.lst and isa.lst path. But you can easily 
  69.     pass this value trough a configure passed argument as 
  70.     '--with-detect-prefix'. 
  71.  
  72.     The next function you should call is init_bus by passing the lst
  73. initialized structure(see below) as argument. This function will detect all
  74. evices presents on the following busses:
  75.  
  76. -ISA
  77. -PCI
  78. -PCMCIA
  79. -USB
  80. -IDE
  81. -SCSI
  82. -PARALLEL
  83. -SERIAL    
  84.   
  85.   +----8<---------------------------------------------------------------
  86.   |bus = init_bus(lst);
  87.   +---------------------------------------------------------------------
  88.  
  89. Now you can use device detection functions. Some functions needs args. some
  90. none.
  91.  
  92.   +----8<---------------------------------------------------------------
  93.   |cpu = cpu_detect();            /* This functions don't use args      */
  94.   |
  95.   |scsiintf = scsinterface_detect(bus);   /* Use bus structure*/
  96.   +----8<---------------------------------------------------------------
  97.   
  98. All devices detected are in a linked list. You can parse it:
  99.  
  100.   +----8<----------------------------------------------------------------    
  101.   | for(;cpu;cpu->next)
  102.   |        printf("I've found a %s %s\n", cpu->vendor, cpu->model);
  103.   +-----------------------------------------------------------------------
  104.  
  105. As you can see detect library is very easy to use. With only few lines you can
  106. add hardware detection feature to your program.
  107.